﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FastShip88
{
    public partial class InboundQuery : System.Web.UI.Page
    {
        DBAccess.UsersDataContext db;

        protected void Page_Load(object sender, EventArgs e)
        {
            db = new DBAccess.UsersDataContext();


        }

        protected void fvSelected_PreRender(object sender, EventArgs e)
        {
            DropDownList ddlShops = (DropDownList) fvSelected.FindControl("ddlShops");
            Label lblShopId = (Label) fvSelected.FindControl("lblShopId");
            ddlShops.SelectedValue = lblShopId.Text;

            DropDownList ddlDeliveryCom = (DropDownList)fvSelected.FindControl("ddlDeliveryCom");
            Label lblDeliveryComId = (Label)fvSelected.FindControl("lblDeliveryComId");
            ddlDeliveryCom.SelectedValue = lblDeliveryComId.Text;
        }

        protected void bthSearch_Click(object sender, EventArgs e)
        {

            BindGridData();

            div_results.Visible = true;
            div_selected.Visible = false;
        }

        private void BindGridData()
        {
            string strParcelNo = txtParcelNo.Text.Trim();
            int userId = Utility.GetUserId(this);
            var parcels = from p in db.ParcelInfos
                          from s in db.ShopInfos
                          where p.ShopId == s.id && p.UserId == userId && p.ParcelNo.Contains(strParcelNo) && p.StatusId == 10
                          select new { p.Id, p.UserId, p.ParcelNo, p.ShopId, s.name, p.Description, p.Weight, p.ArriveDate };


            gvResults.DataSourceID = null;
            gvResults.DataSource = parcels;
            gvResults.DataBind();
        }

        protected void gvResults_SelectedIndexChanged(object sender, EventArgs e)
        {
            int parcelId = SafeConvert.ToInt( gvResults.SelectedValue);

            div_selected.Visible = true;



        }

        protected void gvResults_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvResults.PageIndex = e.NewPageIndex;
            BindGridData();
        }
    }
}
